/**
 * Created by dell on 2015/7/22.
 */

var onceFanDes = function() {

    var saveValue = function() {
        var save = function(thisDom) {
            $.ajax({
                url: basePath + "OnceFan/design/saveValue",
                type:"post",
                dataType:"json",
                data: thisDom.attr("id") + "=" + thisDom.val() + "&paramName=" + thisDom.attr("id") + "&paramValue=" + thisDom.val()
            });
        };
        $("input").on('blur',function() {
            var $this = $(this);
            validate.init($this);
            if (validate.isNotNumber($this.val())) {
                validate.invalid();
                return;
            } else {
                save($this);
                validate.valid();
            }
        });

        $("select").on('change',function() {
            validate.init($(this));
            save($(this));
            validate.valid();
        });
    };

    var calculateInit = function() {
        $.post(basePath + "OnceFan/design/calculateInit",function() {});
    };

    var getRecover = function() {
        $.get(basePath + "OnceFan/design/getRecover",function(data) {
            $("input").autoInject({
                data:data,
                mode:"id"
            });
            Metronic.unblockUI();
        }).done(calculateInit());
    };


    return {
        init:function() {
            Metronic.blockUI({
                boxed:true,
                message:"数据计算中..."
            });
            saveValue();
            getRecover();
        }
    }

}();
